package com.guyj.baseproject.designpatterns.single;

/**
 * Created by guyj on 2019/9/6.
 * 描述: 静态内部类 防克隆 防反序列化
 */

public class MySingletonA {

	private MySingletonA() {
	}

	public static MySingletonA getInstance() {
		return SingletonHolder.sInstance;
	}

	//静态内部类
	private static class SingletonHolder {
		private static final MySingletonA sInstance = new MySingletonA();
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		return SingletonHolder.sInstance;
	}

	private Object readResolve() {
		return SingletonHolder.sInstance;
	}

}
